import lxml.etree as le
import urllib.request as ur

# 读取页面，进行解析
with open('edu.html', 'r', encoding='utf-8')as f:

    html1 = f.read()            # 读取html文件字符串格式

    html_x = le.HTML(html1)     # html文件转换成xpath格式，可以对这个对象进行索引

    div_x_s = html_x.xpath('//div[@class="classify_cList"]')        # 对一级标题进行索引

    data_s = []
    for div_x in div_x_s:
        category1 = div_x.xpath('./h3/a/text()')            # 一级标题
        category2_s = div_x.xpath('./div/span/a/text()')    # 二级标题

        data_s.append(                              # 将一级和二级标题加入空列表内
            {
                'category1': category1,
                'category2_s': category2_s
            }
        )

    # 通过遍历data将一级标题与二级标题输出
    for data in data_s:
        # 输出一级标题 【0】列表的下标取值
        print(data.get('category1')[0])
        # 输出二级标题
        for i in range(3):
            print('   ', data.get('category2_s')[i])

